package com.moter.bigdata.service.impl;

import com.moter.bigdata.dao.JobInfoDao;
import com.moter.bigdata.entity.JobInfo;
import com.moter.bigdata.service.JobInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class JobInfoServiceImpl implements JobInfoService {
    @Autowired
    private JobInfoDao jobInfoDao;

    @Override
    @Transactional
    public void save(JobInfo jobInfo) {
        //判断数据库中是否有 即将添加的数据
        JobInfo param = new JobInfo();
        param.setUrl(jobInfo.getUrl());
        param.setTime(jobInfo.getTime());

        List<JobInfo> query = this.query(param);
        if (query.size() == 0) {
            this.jobInfoDao.saveAndFlush(jobInfo);
        }
    }

    @Override
    public List<JobInfo> query(JobInfo jobInfo) {
        //设置查询条件
        Example example = Example.of(jobInfo);

        List all = this.jobInfoDao.findAll(example);
        return all;
    }
}
